import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import createLogger from 'vuex/dist/logger'
Vue.use(Vuex)
const debug =process.env.NODE_ENV !=='production'
const store= new Vuex.Store({
	state,
	getters:{
		getCount:(state)=>{
			return state.count=state.count<10?"0"+state.count:state.count
		},
		getcurtid:(state)=>{
			let partitionList=window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
			const hasCon=partitionList[state.curtid]
//			console.log(state.curtid)
			if(!hasCon){
				//遍历大对象的属性名(键名)
					const keyArr=Object.keys(partitionList)
//					console.log(keyArr)
	//				核心代码:找tid==obj.tid
					for(let i=0,len=keyArr.length;i<len;i++){
	//					一定要清楚,你访问的元素是什么
						const tmpArr=partitionList[keyArr[i]]
						for(let j=0;j<tmpArr.length;j++){
	//						内循环
//							console.log(tmpArr)
	//						核心代码
							if(tmpArr[j].tid==state.curtid){
								return state.curtid=keyArr[i]
							}
						}
					}
			}else{
				return state.curtid
			}
		}
	},
	mutations:{
		increment(state){
			state.count++
		},
		setcurtid(state,payload){
			//更新state.curTid
			state.curtid=payload.curtid
		}
	},
	plugins:debug? [createLogger()] : []
})
export default store